// Default empty project template
#include "applicationui.hpp"
#include "NetworkManager.h"
#include "Packet.h"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

using namespace bb::cascades;

ApplicationUI::ApplicationUI(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    //create the packet object to send the request
    Packet *packet = new Packet("http://www.webafrica.co.za/wesleytest.aspx");

    //connect to the packet's onsuccess signal
    bool pcon = connect(packet,
						SIGNAL(OnSuccess(QString)),
						this,
						SLOT(ShowResult(QString)));
    Q_ASSERT(pcon);
    Q_UNUSED(pcon);
    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    //bind the label in c++ to point to the qml label
    myLabel = root->findChild<TextArea*>("lblText");
    myLabel->setText("test");

    app->setScene(root);

    packet->PerformRequest();
}

void ApplicationUI::ShowResult(QString result) {
    // create root object for the UI
	myLabel->setText(result);
}

